<template>
  <div>
    <van-nav-bar title="登录" class="nav" />
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="loginname"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          :rules="[
            {
              pattern: usernamePattern,
              message: '请填写用户名-至少三位',
            },
          ]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[
            { pattern: passwordPattern, message: '请填写密码-至少三位' },
          ]"
        />
      </van-cell-group>
      <div style="margin: 16px">
        <van-button
          round
          block
          type="primary"
          native-type="submit"
          @click="loginHandler"
        >
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>
<script setup lang="ts">
import { ref } from "vue";
// 账号密码
let loginname = ref("admin");
let password = ref("123456");
// 账号密码的校验规则
const usernamePattern = /^\w{3,}$/;
const passwordPattern = /^.{3,}$/;

let onSubmit = () => {
  console.log("onSubmit");
};

// 登录
let loginHandler = () => {
  console.log("登录");
};
</script>
<style lang="scss" scoped></style>
